package com.zslc.securitymonitoring.config;

import cn.hutool.core.collection.CollectionUtil;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.server.ServerEndpointConfig.Configurator;
import java.util.List;
import java.util.Map;

/**
 * 获取HttpSession
 * @author Gaoyc
 * @date 2024/05/22 14:06
 */
public class GetHttpSessionConfigurator extends Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec,
                                HandshakeRequest request, HandshakeResponse response) {
        Map<String, List<String>> headers = request.getParameterMap();
        if(CollectionUtil.isNotEmpty(headers)) {
            List<String> userIds = headers.get("busId");
            if(CollectionUtil.isNotEmpty(userIds)) {
                sec.getUserProperties().put("busId", userIds.get(0));
            }
        }
    }

}

